import compRender from "./renderfn";
import { transferEmpty } from "../../utils/tools";
export default {
    inheritAttrs: false,
    props: {
        formdata: Array,
        value: {
            type: Object,
            default() {
                return {}
            }
        },
        align: String,
        col: Number,
        placeholder: String,// 文本占位符
    },
    components: {
        compRender
    },
    methods: {
        handleVisible(item) {
            return item.show !== false && item.span != '0';
        },
        isGroupFormChild(tag = '') {
            // 'vCheckBox', 'Radio', 'Checkbox'
            return ['Radio', 'Checkbox'].indexOf(tag) > -1
        },
        getValueText(item, value) {
            let { valueText, tip = '', options } = item, result;
            if (value != undefined && !valueText && options instanceof Array) {
                const opt = options.find(function (item) {
                    if (typeof item !== 'object') {
                        item = {
                            value: item,
                            label: item,
                        }
                    }
                    return item.value == value || item.trueValue == value || item.falseValue == value;
                }) || {};
                result = opt.label == undefined ? this.placeholder : opt.label;
            }
            return (transferEmpty(result || valueText || value, '') + tip) || this.placeholder || '';
        },
        getColProps(item) {
            let { align, span, offset } = item;
            if (span === undefined) {
                span = parseInt(24 / (parseInt(this.col) || 2));
            }
            if (offset === undefined) {
                const offsetMap = {
                    left: 0,
                    right: parseInt(24 - span),
                    center: parseInt((24 - span) / 2)
                };
                offset = offsetMap[align || this.align || "left"] || 0;
            }
            return {
                span,
                offset
            };
        },
    }
};
